package com.yuexun.dhdoctor.module.commun.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.module.Contract.bean.GroupGroupBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/17 0017.
 */

public class GroupExpandableAdapter extends BaseExpandableListAdapter {

    private Context context;
    List<GroupGroupBean> groupGroupBeen = new ArrayList<>();

    public GroupExpandableAdapter(Context context, List<GroupGroupBean> groupGroupBeen){
        this.context = context;
        this.groupGroupBeen = groupGroupBeen;
    }

    public void setGroupGroupBeen(List<GroupGroupBean> groupGroupBeen) {
        this.groupGroupBeen = groupGroupBeen;
        notifyDataSetChanged();
    }

    @Override
    public int getGroupCount() {
        return null == groupGroupBeen ? 0 : groupGroupBeen.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return groupGroupBeen.get(i).getDatas().size();
    }

    @Override
    public Object getGroup(int i) {
        return groupGroupBeen.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return groupGroupBeen.get(i).getDatas().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        ViewGroupHolder holder;
        if(null == view) {
            view = LayoutInflater.from(context).inflate(R.layout.item_parent, null);
            holder = new ViewGroupHolder();
            holder.groupName = (TextView)view.findViewById(R.id.item_group_name);
            view.setTag(holder);
        } else {
            holder = (ViewGroupHolder)view.getTag();
        }

        holder.groupName.setText(groupGroupBeen.get(i).getGroup_name());
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        ViewChildHolder holder;
        if(null == view) {
            view = LayoutInflater.from(context).inflate(R.layout.item_group, null);
            holder = new ViewChildHolder();
            holder.group_name = (TextView)view.findViewById(R.id.item_group_name);
            holder.group_count = (TextView)view.findViewById(R.id.item_group_count);
            view.setTag(holder);
        } else {
            holder = (ViewChildHolder)view.getTag();
        }

        holder.group_name.setText(groupGroupBeen.get(i).getDatas().get(i1).getTitle());
        holder.group_count.setText(groupGroupBeen.get(i).getDatas().get(i1).getToId().size()+"人");
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    class ViewGroupHolder{
        TextView groupName;
    }

    class ViewChildHolder{
        TextView group_name,group_count;
    }
}
